package org.ayachinene.leetcode.problems;

import org.ayachinene.leetcode.structure.TreeNode;

public class P2331 {

    static class Solution {

        public boolean evaluateTree(TreeNode root) {
            // Leaf
            if (root.left == null || root.right == null) {
                return root.val == 1;
            }

            // OR
            if (root.val == 2) {
                return evaluateTree(root.left) || evaluateTree(root.right);
            }
            // AND
            return evaluateTree(root.left) && evaluateTree(root.right);
        }

    }
}
